package com.kkshop.gwt.registration;

import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.kkshop.gwt.widget.wizard.impl.AbstractWizardPage;

public class DisclaimerWizardPage extends AbstractWizardPage {
    
    private CheckBox agreeCheckBox;
    private TextArea disclaimerText;

    public DisclaimerWizardPage() {
        super(RegistrationController.getInstance().getResources().registerDisclaimerHeader());
    }

    public Widget createWidget() {
        VerticalPanel panel = new VerticalPanel();
        panel.add(getDisclaimerText());
        panel.add(getAgreeCheckBox());
        return panel;
    }

    public boolean isFinished() {
        return getAgreeCheckBox().isChecked();
    }
    
    private TextArea getDisclaimerText() {
        if(disclaimerText == null) {
            disclaimerText = new TextArea();
            disclaimerText.setText(RegistrationController.getInstance().getResources().registerDisclaimerText());
        }
        return disclaimerText;
    }

    private CheckBox getAgreeCheckBox() {
        if(agreeCheckBox == null) {
            agreeCheckBox = new CheckBox("I agree");
            agreeCheckBox.addClickListener(new ClickListener() {
                public void onClick(Widget widget) {
                    doUpdateButtons();
                }
            });
        }
        return agreeCheckBox;
    }
}
